<?php

/**
 * Ads filter form base class.
 *
 * @package    ndirou_affaire
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 29570 2010-05-21 14:49:47Z Kris.Wallsmith $
 */
abstract class BaseAdsFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'town_id'          => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Town'), 'add_empty' => true)),
      'category_id'      => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Category'), 'add_empty' => true)),
      'subcategory_id'   => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('SubCategory'), 'add_empty' => true)),
      'type_id'          => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Type'), 'add_empty' => true)),
      'seller_id'        => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Seller'), 'add_empty' => true)),
      'title'            => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'description'      => new sfWidgetFormFilterInput(),
      'price'            => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'bonplan'          => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'image_path1'      => new sfWidgetFormFilterInput(),
      'image_path2'      => new sfWidgetFormFilterInput(),
      'town'             => new sfWidgetFormFilterInput(),
      'metadescription'  => new sfWidgetFormFilterInput(),
      'metakeywords'     => new sfWidgetFormFilterInput(),
      'metatitle'        => new sfWidgetFormFilterInput(),
      'status_id'        => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'is_prof'          => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'created_at'       => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'updated_at'       => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'publish_start_at' => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'publish_end_at'   => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'slug'             => new sfWidgetFormFilterInput(),
      'adses_list'       => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Seller')),
    ));

    $this->setValidators(array(
      'town_id'          => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Town'), 'column' => 'id')),
      'category_id'      => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Category'), 'column' => 'id')),
      'subcategory_id'   => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('SubCategory'), 'column' => 'id')),
      'type_id'          => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Type'), 'column' => 'id')),
      'seller_id'        => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Seller'), 'column' => 'id')),
      'title'            => new sfValidatorPass(array('required' => false)),
      'description'      => new sfValidatorPass(array('required' => false)),
      'price'            => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'bonplan'          => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'image_path1'      => new sfValidatorPass(array('required' => false)),
      'image_path2'      => new sfValidatorPass(array('required' => false)),
      'town'             => new sfValidatorPass(array('required' => false)),
      'metadescription'  => new sfValidatorPass(array('required' => false)),
      'metakeywords'     => new sfValidatorPass(array('required' => false)),
      'metatitle'        => new sfValidatorPass(array('required' => false)),
      'status_id'        => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'is_prof'          => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'created_at'       => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'updated_at'       => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'publish_start_at' => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'publish_end_at'   => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'slug'             => new sfValidatorPass(array('required' => false)),
      'adses_list'       => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Seller', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('ads_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addAdsesListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.SellerAds SellerAds')
      ->andWhereIn('SellerAds.seller_id', $values)
    ;
  }

  public function getModelName()
  {
    return 'Ads';
  }

  public function getFields()
  {
    return array(
      'id'               => 'Number',
      'town_id'          => 'ForeignKey',
      'category_id'      => 'ForeignKey',
      'subcategory_id'   => 'ForeignKey',
      'type_id'          => 'ForeignKey',
      'seller_id'        => 'ForeignKey',
      'title'            => 'Text',
      'description'      => 'Text',
      'price'            => 'Number',
      'bonplan'          => 'Boolean',
      'image_path1'      => 'Text',
      'image_path2'      => 'Text',
      'town'             => 'Text',
      'metadescription'  => 'Text',
      'metakeywords'     => 'Text',
      'metatitle'        => 'Text',
      'status_id'        => 'Boolean',
      'is_prof'          => 'Boolean',
      'created_at'       => 'Date',
      'updated_at'       => 'Date',
      'publish_start_at' => 'Date',
      'publish_end_at'   => 'Date',
      'slug'             => 'Text',
      'adses_list'       => 'ManyKey',
    );
  }
}
